﻿using System;

namespace SmartCity.Shared
{
    /// <summary>
    /// 输出基类
    /// </summary>
    public class ActionResponse
    {
        /// <summary>状态码</summary>
        public ResponseCode Code { get; protected set; }

        /// <summary>消息内容</summary>
        public string Msg { get; protected set; }

        /// <summary>
        /// 成功
        /// </summary>
        public static ActionResponse Successful()
        {
            return new ActionResponse()
            {
                Code = ResponseCode.正常,
                Msg = "操作成功"
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg"></param>
        public static ActionResponse Failed(string msg)
        {
            return new ActionResponse()
            {
                Code = ResponseCode.正常,
                Msg = msg
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        public static ActionResponse Failed(ResponseCode code, string msg)
        {
            return new ActionResponse()
            {
                Code = code,
                Msg = msg
            };
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="msg"></param>
        public static ActionResponse Wrong(string msg)
        {
            return new ActionResponse()
            {
                Code = ResponseCode.系统异常,
                Msg = msg
            };
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="ex"></param>
        public static ActionResponse Wrong(Exception ex)
        {
            return new ActionResponse()
            {
                Code = ResponseCode.系统异常,
                Msg = ex.Message
            };
        }
    }

    /// <summary>
    /// 输出基类
    /// </summary>
    /// <typeparam name="TResponse"></typeparam>
    public class ActionResponse<TResponse> where TResponse : ActionResponse<TResponse>, new()
    {
        /// <summary>状态码</summary>
        public ResponseCode Code { get; protected set; }

        /// <summary>消息内容</summary>
        public string Msg { get; protected set; }

        /// <summary>
        /// 成功
        /// </summary>
        public static TResponse Successful()
        {
            return new TResponse()
            {
                Code = ResponseCode.正常,
                Msg = "操作成功"
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg"></param>
        public static TResponse Failed(string msg)
        {
            return new TResponse()
            {
                Code = ResponseCode.正常,
                Msg = msg
            };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        public static TResponse Failed(ResponseCode code, string msg)
        {
            return new TResponse()
            {
                Code = code,
                Msg = msg
            };
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="msg"></param>
        public static TResponse Wrong(string msg)
        {
            return new TResponse()
            {
                Code = ResponseCode.系统异常,
                Msg = msg
            };
        }

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="ex"></param>
        public static TResponse Wrong(Exception ex)
        {
            return new TResponse()
            {
                Code = ResponseCode.系统异常,
                Msg = ex.Message
            };
        }
    }
}